package com.bing.controller.advice;

import com.bing.bean.ResultMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by kaibb on 15-12-25.
 */

@ControllerAdvice
public class ExceptionAdvice {
    public static final Logger LOGGER = LoggerFactory.getLogger(ExceptionAdvice.class);
    private ResultMsg createResult() {
        return new ResultMsg();
    }

    @ExceptionHandler(Throwable.class)
    @ResponseBody
    public ResultMsg handleAjaxException(Throwable throwable) {
        throwable.printStackTrace();
        ResultMsg resultMsg = createResult();
        resultMsg.setStatusCode(500);
        resultMsg.setMessage(throwable.getMessage());
        return resultMsg;
    }
}
